<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
</body>
<script>
    // 1.大括号创建对象
    // 类似python的字典
    var obj1 = {
        name:'zxy',
        age:20,
        email:'232131@31231'
    }
    // 控制台打印输出
    console.log(obj1)
    // 2.内置构造函数创建
    var obj2 = new Object()
    obj2.name = 'fdsafa'
    obj2.age = 12
    console.log(obj2)
    //操作对象
    var obj3 ={
        name:'xhx',
        age:18,
        email:'2979@'
    }
    var name = obj3.name
    // 通过.来获取
    console.log('名字: '+name)
    // 通过键名来获取
    console.log('名字: '+obj3['name'])
    // 多层相当于python的字典的嵌套
    var person = {
        name:'zxy',
        friend:{
            'xhx':{
                girlfriend:'cy'
            },
            'xt':{
                age:18
            }
        }
    }
    console.log(person['friend'])
    console.log(person['friend']['xhx']['girlfriend'])
    //通过循环来遍历对象中的键
    for (var k in person){
        console.log(k)
    }
    for (var k in person){
        // 判断内容是否还是一个对象
        if(typeof person[k] === 'object'){
            // 遍历最外层对象内aaaa部的对象内容
            for(var key in person[k]){
                console.log(person[k][key])
            }
        }
    }
    // 元素全为对象的列表
    var array = [{name:'zxy',age:18},{name:'xhx',age:20},{name:'xt',age:20}]
    for (var i = 0;i<array.length;i++){
        console.log(array[i])
    }
    // 先遍历出列表中每个对象
    // 然后遍历对象中的内容
    for(var i =0;i<array.length;i++){
        for(var k in array[i]){
            console.log(array[i][k])
        }
    }
    var num_array = [1,2,3,6,5,4]
    // 冒泡排序
    for(var i =0;i<num_array.length;i++){
        for(var j =0;j<num_array.length;j++){
            if(num_array[j]>num_array[j+1]){
                var temp = num_array[j]
                num_array[j] = num_array[j+1]
                num_array[j+1] = temp
            }
        }
    }
    console.log(num_array)
</script>
</html>